package com.tiku.controller;

import com.tiku.common.ResultJson;
import com.tiku.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * 用户参数相关
 */
@RestController
@RequestMapping("/userParam")
@Api("用户参数相关接口")
@CrossOrigin("*")
public class UserParamController {

    @Autowired
    private UserInfoService userInfoService;



    @PostMapping("/upAvatar")
    @ApiOperation("上传头像")
    public ResultJson upAvatar( @RequestParam("file") MultipartFile avatarFile){
        return userInfoService.upAvatar(avatarFile);
    }


    @GetMapping("/sex/{sex}")
    @ApiOperation("更改性别")
    public ResultJson upSex(@PathVariable("sex") Integer sex){
       return userInfoService.upSex(sex);
    }

    @PostMapping("/nickName/{nickName}")
    @ApiOperation("更改昵称")
    public ResultJson upNickName(@PathVariable("nickName") String nickName){
        return userInfoService.upNickName(nickName);
    }

    @GetMapping("/getUserParam")
    @ApiOperation("获取用户基本信息")
    public ResultJson getUserParam(){
        return userInfoService.getUserParam();
    }

    @PostMapping("/updatePhone")
    @ApiOperation("更改手机号")
    public ResultJson updatePhone(Map<String,String> map){
        String phone = map.get("phone");
        String code = map.get("code");

        return userInfoService.updatePhone(phone,code);
    }

    @GetMapping("/updateToDay/{day}")
    public ResultJson updateToDay(@PathVariable("day") String day){
        return userInfoService.updateToDay(day);
    }

}
